from django.conf import settings
import urllib

def fetch_app_access_token():
  path = 'https://graph.facebook.com/oauth/access_token'
  params = {
    'client_id': settings.FACEBOOK_APP_ID,
    'client_secret': settings.FACEBOOK_APP_SECRET,
    'grant_type': 'client_credentials'
  }
  uri = '%s?%s' % (path, urllib.urlencode(params))
  response = urllib.urlopen(uri)
  data = response.read()
  
  # The response will be of the form "access_token=abajd12123..."
  token = data.split('=')[1]
  return token
  